import redis

HOST = 'localhost'
PORT = '6379'


class RedisClient(object):

    def __init__(self, host=HOST, port=PORT):
        pool = redis.ConnectionPool(host=host, port=port, decode_responses=True)
        self.client = redis.Redis(connection_pool=pool)

    def get_redis(self):
        return self.client

    def set(self, key, value):
        return self.client.set(key, value)

    def set_ex(self, key, value, ex):
        return self.client.setex(key, ex, value)

    def get(self, key):
        return self.client.get(key)

    def remove(self, key):
        return self.client.delete(key)

    def is_exist(self, key):
        return self.client.exists(key) == 1


if __name__ == '__main__':
    client = RedisClient()
    # print(client.set('name', 'wenchao'))
    # print(client.remove('name'))
    # print(client.get('name'))
    # print(client.get_redis().keys())
    # print(client.set_ex('name', 'super', 3))
    print(client.is_exist('k2'))
